/**
 * Created by LUJIAN on 2016/4/21.
 */

var gulp = require('gulp');
var paths = require('./../config/path');
var path = require('path');
var less = require('gulp-less');
var cleanCSS = require('gulp-clean-css');
var sourceMaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var jetpack = require('fs-jetpack');
var srcDir = jetpack.cwd('./src');
var destDir = jetpack.cwd('./build');

gulp.task('clean', function(){
  destDir.dirAsync('.', {empty: true});
});

gulp.task('style', ['clean'], function(){
  return gulp.src('src/stylesheets/*.less')
    .pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
    .pipe(less())
    .pipe(gulp.dest('build/css'))
});

gulp.task('minify-css', ['style'], function(){
  return gulp.src('build/css/*.css')
    .pipe(sourceMaps.init())
    .pipe(cleanCSS())
    .pipe(sourceMaps.write())
    .pipe(gulp.dest('build/css'));
});

gulp.task('default', ['minify-css']);